package controllers

import (
	"gdshop-font-api-go/app/request/UserRequest"
	UserResponse "gdshop-font-api-go/app/response/UserResponse"
	"gdshop-font-api-go/app/service/UserService"
	"gdshop-font-api-go/library/response"
	toolsDb "gdshop-font-api-go/library/tools/db"
	"github.com/gogf/gf/net/ghttp"
)

type TestV2Controller struct {
	*BaseController
}

func (c *TestV2Controller) Index(r *ghttp.Request) *response.JsonResponse {
	user := toolsDb.GetUnSafaTableAddDeleteWhere(r.GetCtx(), "Member")
	//UserResponse.Where("delete_at < ?", 1)
	userList := ([]UserResponse.List)(nil)
	err := user.Structs(&userList)
	if err != nil {
		return response.FailByRequestMessage(r, err.Error())
	} else {
		return response.SuccessByRequestMessageData(r, "成功", userList)
	}
}

func (c *TestV2Controller) Add(r *ghttp.Request) *response.JsonResponse {
	var parames *UserRequest.Add
	if err := r.Parse(&parames); err != nil {
		return response.FailByRequestMessage(r, err.Error())
	}
	return UserService.Add(r.GetCtx(), parames)
}

func (c *TestV2Controller) Test(r *ghttp.Request) {
	response.JsonExit(r, 0, "test V2")
}
